﻿#include "SurfaceElectricFieldMapSettingData.h"
#include "BaseModule/GlobalHelper.h"
namespace pst
{
    SurfaceElectricFieldMapSettingData::SurfaceElectricFieldMapSettingData(QObject* parent, int id)
        : QObject(parent)
        , m_scalarBarSettingData(nullptr)
        , m_geometrySettingData(nullptr)
        , m_resultDataSettingData(nullptr)
        , m_cubeAxesActorSettingData(nullptr)
        , m_id(id)
    {
    }

    SurfaceElectricFieldMapSettingData::~SurfaceElectricFieldMapSettingData()
    {
    }

    int SurfaceElectricFieldMapSettingData::getID() const
    {
        return m_id;
    }

    void pst::SurfaceElectricFieldMapSettingData::setScalarBarSettingData(ScalarBarSettingData* scalarBarSettingData)
    {
        m_scalarBarSettingData = scalarBarSettingData;
    }

    ScalarBarSettingData* SurfaceElectricFieldMapSettingData::getScalarBarSettingData() const
    {
        return m_scalarBarSettingData;
    }

    void pst::SurfaceElectricFieldMapSettingData::setGeometrySettingData(GeometrySettingData* geometrySettingData)
    {
        m_geometrySettingData = geometrySettingData;
    }

    GeometrySettingData* SurfaceElectricFieldMapSettingData::getGeometrySettingData() const
    {
        return m_geometrySettingData;
    }

    void SurfaceElectricFieldMapSettingData::setResultDataSettingData(ResultDataSettingData* resultDataSettingData)
    {
        m_resultDataSettingData = resultDataSettingData;
    }

    ResultDataSettingData* SurfaceElectricFieldMapSettingData::getResultDataSettingData() const
    {
        return m_resultDataSettingData;
    }

    void SurfaceElectricFieldMapSettingData::setCubeAxesActorSettingData(CubeAxesActorSettingData* cubeAxesActorSettingData)
    {
        m_cubeAxesActorSettingData = cubeAxesActorSettingData;
    }

    CubeAxesActorSettingData* SurfaceElectricFieldMapSettingData::getCubeAxesActorSettingData()
    {
        return m_cubeAxesActorSettingData;
    }

    QDomElement& SurfaceElectricFieldMapSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _SurfaceElectricFieldMapSettingDataRoot = doc->createElement("SurfaceElectricFieldMapSettingData");
        QDomAttr idattr = doc->createAttribute("SurfacePlotSettingDataID");
        idattr.setValue(QString::number(m_id));
        _SurfaceElectricFieldMapSettingDataRoot.setAttributeNode(idattr);

        if (m_scalarBarSettingData != nullptr)
            m_scalarBarSettingData->writeToProjectFile(doc, &_SurfaceElectricFieldMapSettingDataRoot, isdiso);
        if (m_geometrySettingData != nullptr)
            m_geometrySettingData->writeToProjectFile(doc, &_SurfaceElectricFieldMapSettingDataRoot, isdiso);
        if (m_resultDataSettingData != nullptr)
            m_resultDataSettingData->writeToProjectFile(doc, &_SurfaceElectricFieldMapSettingDataRoot, isdiso);
        if (m_cubeAxesActorSettingData != nullptr)
            m_cubeAxesActorSettingData->writeToProjectFile(doc, &_SurfaceElectricFieldMapSettingDataRoot, false, isdiso);

        element->appendChild(_SurfaceElectricFieldMapSettingDataRoot);

        return _SurfaceElectricFieldMapSettingDataRoot;
    }

    void SurfaceElectricFieldMapSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        m_id = element->attribute("SurfacePlotSettingDataID").toInt();
        auto _ScalarBarSettingDataEle = element->elementsByTagName("ScalarBarSettingData");
        auto _GeometrySettingDataEle = element->elementsByTagName("GeometrySettingData");
        auto _ResultDataSettingDataEle = element->elementsByTagName("ResultDataSettingData");
        auto _CubeAxesActorSettingDataEle = element->elementsByTagName("CubeAxesActorSettingData");

        if (m_scalarBarSettingData != nullptr)
            m_scalarBarSettingData->readFromProjectFile(&_ScalarBarSettingDataEle.at(0).toElement(), isdiso);
        if (m_geometrySettingData != nullptr)
            m_geometrySettingData->readFromProjectFile(&_GeometrySettingDataEle.at(0).toElement(), isdiso);
        if (m_resultDataSettingData != nullptr)
            m_resultDataSettingData->readFromProjectFile(&_ResultDataSettingDataEle.at(0).toElement().toElement(), isdiso);
        if (m_cubeAxesActorSettingData != nullptr)
            m_cubeAxesActorSettingData->readFromProjectFile(&_CubeAxesActorSettingDataEle.at(0).toElement(), false, isdiso);
    }

    GeometrySettingData::GeometrySettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void GeometrySettingData::setGeometryTransparency(int transparency)
    {
        m_transparency = transparency;
    }

    int GeometrySettingData::getGeometryTransparency() const
    {
        return m_transparency;
    }

    QDomElement& GeometrySettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _GeometrySettingDataRoot = doc->createElement("GeometrySettingData");

        GlobalHelperInstance->createDomElement(doc, &_GeometrySettingDataRoot, "Transparency", QString::number(m_transparency));

        element->appendChild(_GeometrySettingDataRoot);

        return _GeometrySettingDataRoot;
    }

    void GeometrySettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        auto _TransparencyNodeList = element->elementsByTagName("Transparency");
        m_transparency = _TransparencyNodeList.item(0).toElement().text().toInt();
    }

    ResultDataSettingData::ResultDataSettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void ResultDataSettingData::setResultDataName(QString resultName)
    {
        m_resultName = resultName;
    }

    QString ResultDataSettingData::getResultDataName() const
    {
        return m_resultName;
    }

    void ResultDataSettingData::setResultDataTransparency(int transparency)
    {
        m_transparency = transparency;
    }

    int ResultDataSettingData::getResultDataTransparency() const
    {
        return m_transparency;
    }

    void ResultDataSettingData::setResultDataScaleFactor(double scaleFactor)
    {
        m_scaleFactor = scaleFactor;
    }

    double ResultDataSettingData::getResultDataScaleFactor() const
    {
        return m_scaleFactor;
    }

    QDomElement& ResultDataSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _ResultDataSettingDataRoot = doc->createElement("ResultDataSettingData");

        GlobalHelperInstance->createDomElement(doc, &_ResultDataSettingDataRoot, "ResultName", m_resultName);
        GlobalHelperInstance->createDomElement(doc, &_ResultDataSettingDataRoot, "Transparency", QString::number(m_transparency));
        GlobalHelperInstance->createDomElement(doc, &_ResultDataSettingDataRoot, "ScaleFactor", QString::number(m_scaleFactor));

        element->appendChild(_ResultDataSettingDataRoot);

        return _ResultDataSettingDataRoot;
    }

    void ResultDataSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        auto _ResultNameNodeList = element->elementsByTagName("ResultName");
        m_resultName = _ResultNameNodeList.item(0).toElement().text();
        auto _TransparencyNodeList = element->elementsByTagName("Transparency");
        m_transparency = _TransparencyNodeList.item(0).toElement().text().toInt();
        auto _ScaleFactorNodeList = element->elementsByTagName("ScaleFactor");
        m_scaleFactor = _ScaleFactorNodeList.item(0).toElement().text().toDouble();
    }


    CubeAxesActorSettingData::CubeAxesActorSettingData(QObject* parent)
        :QObject(parent)
    {
    }

    void CubeAxesActorSettingData::setVisibility(bool isVis)
    {
        m_isVisibility = isVis;
    }

    bool CubeAxesActorSettingData::getVisibility() const
    {
        return m_isVisibility;
    }

    QDomElement& CubeAxesActorSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isFormWindow, bool isdiso)
    {
        QString ElementName = "CubeAxesActorSettingData";
        if (isFormWindow)
        {
            ElementName = "CubeAxesActorSettingDataFromWindow";
        }

        QDomElement _CubeAxesActorSettingDataRoot = doc->createElement(ElementName);

        GlobalHelperInstance->createDomElement(doc, &_CubeAxesActorSettingDataRoot, "IsVisibility", QString::number(m_isVisibility));

        element->appendChild(_CubeAxesActorSettingDataRoot);

        return _CubeAxesActorSettingDataRoot;
    }

    void CubeAxesActorSettingData::readFromProjectFile(QDomElement* element, bool isFormWindow, bool isdiso)
    {
        auto _IsVisibilityNodeList = element->elementsByTagName("IsVisibility");
        m_isVisibility = (bool)_IsVisibilityNodeList.item(0).toElement().text().toInt();
    }

}
